﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace CapturarObjetos.Cenas
{
    public class Cena_Saindo
    {
        Texture2D BotaoSaindo;
        Texture2D BotaoSim;
        Texture2D BotaoNao;
        Texture2D ponteiroImagem;

        int ponteiroPosX;
        int ponteiroPosY;

        //int botaoArrastaY;
        //int botaoArrastaX;

        GameWindow Window;
        Vector2 posicaoSaindo;
       // Vector2 posicaoSim;
       // Vector2 posicaoNao;

        bool ponteiroVisivel = true;
        //bool SairArrastado = false;

        public enum TrocaOpcaoSair
        {
            Normal,
            SimClicado,
            NaoClicado,
        }

        TrocaOpcaoSair trocaSair = TrocaOpcaoSair.Normal;

        
        public Cena_Saindo(ContentManager Content, GameWindow Window)
        {
            BotaoSaindo = Content.Load<Texture2D>("FundoSair");
            BotaoSim = Content.Load<Texture2D>("BotaoSim");
            BotaoNao = Content.Load<Texture2D>("BotaoNao");
            ponteiroImagem = Content.Load<Texture2D>("ponteiro");

            this.posicaoSaindo = new Vector2(200, 200);
            //this.posicaoSim = new Vector2(200, 280);
            //this.posicaoNao = new Vector2(200, 280);

            this.Window = Window;

            
        }

        public void Update(GameTime gameTime, KeyboardState teclado_atual, KeyboardState teclado_anterior, MouseState mouse_atual, MouseState mouse_anterior)
        {
            ponteiroPosX = mouse_atual.X;
            ponteiroPosY = mouse_atual.Y;

            
            //if (SairArrastado == true)
            //{
            //    Window.Title = "aa";
            //this.botaoArrastaX = mouse_atual.X;
            //this.botaoArrastaY = mouse_atual.Y;
            //}
            //////////////////////////////BOTAO SIM///////////////////////////////////////
            if (mouse_atual.LeftButton == ButtonState.Pressed)// && trocaSair == TrocaOpcaoSair.Normal)
            {
                if (new Rectangle(210, 285, 175, 82).Contains(mouse_atual.X, mouse_atual.Y))
                {
                    trocaSair = TrocaOpcaoSair.SimClicado;
                }
            }
            else
            {
                trocaSair = TrocaOpcaoSair.Normal;
            }
            if (mouse_anterior.LeftButton == ButtonState.Pressed && mouse_atual.LeftButton == ButtonState.Released)
            {
                if (new Rectangle(210, 285, 175, 82).Contains(mouse_atual.X, mouse_atual.Y))
                {
                    //Game1.cenaAtual = Game1.Cenas.SAINDO;
                    Game1.sair = true;
                }
            }
            if (mouse_atual.LeftButton == ButtonState.Pressed)
            {
                if (!new Rectangle(210, 285, 175, 82).Contains(mouse_atual.X, mouse_atual.Y))
                {
                    trocaSair = TrocaOpcaoSair.Normal;

                }
            }
            if (teclado_atual.IsKeyDown(Keys.Y))
            {
                Game1.sair = true;
            }

            ////////////////////BOTAO NAO////////////////////////////
            if (mouse_atual.LeftButton == ButtonState.Pressed)// && trocaSair == TrocaOpcaoSair.Normal)
            {
                if (new Rectangle(396, 285, 175, 82).Contains(mouse_atual.X, mouse_atual.Y))
                {
                    trocaSair = TrocaOpcaoSair.NaoClicado;
                }
            }
            else
            {
                trocaSair = TrocaOpcaoSair.Normal;
            }
            if (mouse_anterior.LeftButton == ButtonState.Pressed && mouse_atual.LeftButton == ButtonState.Released)
            {
                if (new Rectangle(396, 285, 175, 82).Contains(mouse_atual.X, mouse_atual.Y))
                {
                    Game1.cenaAtual = Game1.Cenas.FASE01;

                }
            }

            if (mouse_atual.LeftButton == ButtonState.Pressed && trocaSair == TrocaOpcaoSair.NaoClicado)
            {
                if (!new Rectangle(396, 285, 175, 82).Contains(mouse_atual.X, mouse_atual.Y))
                {
                    trocaSair = TrocaOpcaoSair.Normal;

                }
            }
            if (teclado_atual.IsKeyDown(Keys.N))
            {
                Game1.cenaAtual = Game1.Cenas.FASE01;
            }

            //if (mouse_atual.LeftButton == ButtonState.Pressed)
            //{
            //    if(new Rectangle(200,200,380,192).Contains(mouse_atual.X,mouse_atual.Y))
            //    {
            //        SairArrastado = true;
            //    }
            //}

        }
        public void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            switch (trocaSair)
            {
                case TrocaOpcaoSair.Normal:
                    spriteBatch.Draw(BotaoSaindo, posicaoSaindo, Color.White);
                    spriteBatch.Draw(BotaoSim, new Rectangle(210,285,175,82), new Rectangle(2,2,177,84), Color.White);
                    spriteBatch.Draw(BotaoNao, new Rectangle(396,285,175,82), new Rectangle(2,2,177,84), Color.White);
                    break;
                case TrocaOpcaoSair.SimClicado:
                    spriteBatch.Draw(BotaoSaindo, posicaoSaindo, Color.White);
                    spriteBatch.Draw(BotaoSim, new Rectangle(210,285,175,82), new Rectangle(247,2,177,84), Color.White);
                    spriteBatch.Draw(BotaoNao, new Rectangle(396,285,175,82), new Rectangle(2,2,177,84), Color.White);
                    break;
                case TrocaOpcaoSair.NaoClicado:
                    spriteBatch.Draw(BotaoSaindo, posicaoSaindo, Color.White);
                    spriteBatch.Draw(BotaoSim, new Rectangle(210,285,175,82), new Rectangle(2,2,177,84), Color.White);
                    spriteBatch.Draw(BotaoNao, new Rectangle(396,285,175,82), new Rectangle(247,2,177,84), Color.White);
                    break;
            }
            //spriteBatch.Draw(BotaoSaindo, posicaoSaindo, Color.White);
            //spriteBatch.Draw(BotaoSim, posicaoSim, Color.White);
            //spriteBatch.Draw(BotaoNao, posicaoNao, Color.White);
            if (ponteiroVisivel)
                spriteBatch.Draw(ponteiroImagem, new Vector2(ponteiroPosX, ponteiroPosY), Color.White);
        }
    }
}
